import { request } from 'umi';

/**
 * 用户列表
 * @param params
 * @param options
 * @returns
 */
export async function listAdminUser(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
    username?: string;
    name?: string;
  },
  options?: Record<string, any>,
) {
  return request<ADMIN.AdminUserList>('/v1/admin/lists', {
    method: 'POST',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/**
 * 新增用户
 * @param body
 * @param options
 * @returns
 */
export async function addAdminUser(body: ADMIN.AdminUser, options?: Record<string, any>) {
  return request<ADMIN.AdminUser>('/v1/admin/create', {
    method: 'POST',
    data: {
      ...body,
    },
    ...(options || {}),
  });
}

/**
 * 修改用户
 * @param body
 * @param options
 * @returns
 */
export async function editAdminUser(
  id: number | undefined,
  body: ADMIN.AdminUser,
  options?: Record<string, any>,
) {
  return request<ADMIN.AdminUser>('/v1/admin/update/' + id, {
    method: 'PUT',
    data: {
      ...body,
    },
    ...(options || {}),
  });
}

/**
 * 删除用户
 * @param id
 * @param options
 * @returns
 */
export async function deleteAdminUser(id: number | undefined, options?: Record<string, any>) {
  return request<ADMIN.Success>('/v1/admin/delete/' + id, {
    method: 'DELETE',
    ...(options || {}),
  });
}
